import requests


def get_access_token(corpid="ww5719d089888fb0f0", corpsecret="1S8sD7GDLhXfgUovpwy0UcUY9NK_iQFLZfnbMMHoe8o"):
    url = " https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={}&corpsecret={}".format(corpid, corpsecret)
    res = requests.get(url)
    return res.json()


def wechat_department_list(access_token):
    url = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={}&id=ID".format(
        access_token["access_token"])
    res = requests.get(url)
    department_list = res.json()["department"]
    branch_list = [{k: v for k, v in i.items() if k not in ['order', 'department_leader']} for i in department_list]
    return branch_list


access_token = get_access_token()
_list = wechat_department_list(access_token)
